const url = 'https://r.leaguenewway.com'
// const url = 'http://192.168.31.11:3000'

let featchCount = 0

function fetch_(method, fuc, data) {
	return new Promise((resolve, reject) => {
		if (featchCount == 0) {
			// uni.showLoading({
			// 	title: '加载中'
			// });
		}
		featchCount++
		uni.request({
			url: `${url}/${fuc}`,
			data,
			method,
			withCredentials: true,
			enableCookie: true,
			header: {
				// #ifdef !H5 
				cookie: uni.getStorageSync("cookie")
				// #endif
			},
			success: (res) => {
				if (res.header['Set-Cookie'])
					uni.setStorageSync("cookie", res.header['Set-Cookie'])
				resolve(res)
			},
			fail: (res) => {
				reject(res)
			},
			complete: () => {
				featchCount--
				if (featchCount == 0) {
					// uni.hideLoading();
				}
			}
		});
	})
}

function get_(fuc, data) {
	return fetch_('GET', fuc, data)
}

function post_(fuc, data) {
	return fetch_('POST', fuc, data)
}


module.exports = {
	getSwiper(type_id) {
		return get_('newVideoInfo/getSwiper', {
			type_id
		})
	},
	getList(parms) {
		return get_('newVideoInfo/getList', parms)
	},
	getClass() {
		return get_('newVideoInfo/getClass')
	},
	getComment(parms) {
		return get_('newVideoInfo/getComment', parms)
	},
	postComment(parms) {
		return post_('newVideoInfo/postComment', parms)
	},
	getUserInfo() {
		return get_('newVideoInfo/getUserInfo')
	},
	login(parms) {
		return post_('newVideoInfo/login', parms)
	},
	register(parms) {
		return post_('newVideoInfo/register', parms)
	},
	getVideoHistry(parms){
		return get_('newVideoInfo/getVideoHistry', parms)
	},
	upVideoHistry(parms){
		return post_('newVideoInfo/upVideoHistry', parms)
	},
	loginOut(){
		return post_('newVideoInfo/loginOut')
	},
	configGet(parms){
		return get_('newVideoInfo/configGet',parms)
	}
}